<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header">
    <h1>制作件清单明细</h1>
</section>
<section class="content">
    <input id="sheetId" type="hidden" th:value="${makeSheet.id}">
    <input id="makeSheetType" type="hidden" th:value="${makeSheet.sheetType}">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-body" >
                    <div class="col-xs-12">
                        <div class="col-xs-12">
                            <div class="form-inline">
                                <a shiro:hasPermission="production:list:cha" href="javascript:void(0);"
                                   class="btn btn-success pull-right" style="margin-right: 10px"
                                   onclick="selected()">
                                    <span class="Bold">确定</span>
                                </a>
                            </div>
                            <table id="bootstrap-table"></table>

                        </div>
                    </div>

                </div>

            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    ;
    let table, columns,
        sheetId = +$("#sheetId").val();
        sheetType = +$("#makeSheetType").val();

    /** 选择需要变更的制作见清单 */
    function selected() {

        let arr = js.table.selectColumns(table, "id");
        if (arr.length < 1) {
            js.modal.alert("请选择要变更的计划");
            return;
        }
        // location.href = ctx + 'production/list/changePage?sheetId=' + sheetId + '&ids='+arr
        location.href = ctx + 'production/list/changePageResult?sheetId=' + sheetId + '&ids='+arr

    }

    /** 选择计划提报类型 */
    function handlerPage() {
                if (sheetType === 1) {
                    columns = [
                        {checkbox: true,
                            formatter: function (value, row) {
                                if (row.changeStatus === 1) {
                                    return {disabled: true}
                                } else {
                                    return {disabled: false}
                                }
                            }
                        },
                        {title: "图号", field: 'drawNo'},
                        {title: "图名", field: 'drawName'},
                        {title: "数量", field: 'drawNum'},
                        {title: "制作件类型", field: 'makeType'},
                        {title: "备注", field: 'remark'},
                        {title: "附件", field: 'url',
                            formatter: function (value) {
                                if (value) {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                                return '';
                            }
                        }
                    ];
                } else {
                    columns = [
                        {
                            checkbox: true,
                            formatter: function (value, row) {
                                if (row.changeStatus === 1) {
                                    return {disabled: true}
                                } else {
                                    return {disabled: false}
                                }
                            }
                        },
                        {title: "原图号", field: 'drawNo'},
                        {title: "原图名", field: 'drawName'},
                        {title: "原数量", field: 'drawNum'},
                        {title: "原制作件类型", field: 'makeType'},
                        {title: "原备注", field: 'remark'},
                        {title: "原附件", field: 'url',
                            formatter: function (value) {
                                if (value) {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                                return '';
                            }
                        },
                        {title: "新图号", field: 'afterDrawNo',
                            formatter: function (value, row) {
                                if (value === row.drawNo) {
                                    return '<span>' + value + '</span>';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新图名", field: 'afterDrawName',
                            formatter: function (value, row) {
                                if (value === row.drawName) {
                                    return '<span>' + value + '</span>';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新数量", field: 'afterDrawNum',
                            formatter: function (value, row) {
                                if (value === row.drawNum) {
                                    return '<span>' + value + '</span>';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新制作件类型", field: 'afterMakeType',
                            formatter: function (value, row) {
                                if (value === row.makeType) {
                                    return '<span>' + value + '</span>';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新备注", field: 'afterRemark',
                            formatter: function (value, row) {
                            if(!value){
                                return '';
                            }
                                if (value === row.remark) {
                                    return '<span>' + value + '</span>';
                                } else {
                                    return '<span class="text-red">' + value + '</span>';
                                }
                            }
                        },
                        {title: "新附件", field: 'afterUrl',
                            formatter: function (value, row) {
                                if (value === row.url) {
                                    return '';
                                } else {
                                    return '<a target="_blank" href="' + value + '">下载</a>'
                                }
                            }
                        }
                    ];
                }
    }

    $(function () {
;
        handlerPage();

        /** 加载列表 */
        table = js.table.init({
            url: sheetType === 1 ? ctx + "production/list/planList/" + sheetId : ctx + "production/list/changeList/" + sheetId,
            // url: ctx + "production/list/makeResultList/"+sheetId,
            showExport: false,
            columns: columns
        });

    });
</script>
</body>
</html>
